package XMLCreator;

import javax.xml.stream.*;

import DisplayDatas.*;

public class XMLCreateAnswer extends XMLCreatorListOfArticles<SearchResultToDisplay> {

	protected void buildXMLInner(SearchResultToDisplay item)
			throws XMLStreamException {
		super.buildXMLInner(item);
		buildXMLTopics(item,0);		
	}
	
	private void buildXMLOneTopic(TopicToDisplay topic,int level) throws XMLStreamException{
//		System.out.println("XMLCreateAnswer.buildXMLOneTopic");//TODO
		startNode("topic");
		createDetail("id",topic.getId()+"");
		createDetail("name",topic.getName());
		createDetail("level",level+"");
		createDetail("countFound",topic.getCountFound()+"");
		for(TopicToDisplay topicSan : topic.getChildren()){
			buildXMLOneTopic(topicSan,level+1);
		}
		finishNode("topic");
	}

	private void buildXMLTopics(SearchResultToDisplay item,int level) throws XMLStreamException{
		for(TopicToDisplay topic : item.getRoots()){
			buildXMLOneTopic(topic,level);
		}
	}
}
